package main;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * Land sets land types, stores various objects on land
 * @author 12817152
 *
 */
public class Land {
	//field
	int FOREST = 1;
	int WATER = 2;
	int ARABLE = 3;
	int DESERT = 4;
	int threshold = 50; //greater than 50 meters is mountain

	int type;
	int height;
	int weight; //weighting for Dijstra's pathfinding
	Unit unit;
	Colony colony;
	City city;

	/**
	 * constructor
	 * @param landType - type of land i.e. water, forest, etc
	 * @param landHeight - height (not used)
	 */
	public Land(int landType, int landHeight) {
		type = landType;
		height = landHeight;
		switch(type) {
		case 1: weight = 2;
		break;
		case 2: weight = 32768;
		break;
		case 3: weight = 1;
		break;
		case 4: weight = 5;
		break;
		default: weight = 1;
		break;
		}
		if(height > threshold)
			weight += 3;
	}

	/**
	 * returns color based on land type
	 * @return color
	 */
	public Color getColor() {
		switch(type) {
		case 1:
			return new Color(51,102,0);
		case 2:
			return new Color(0,179,255);
		case 3:
			return new Color(102,102,51);
		case 4:
			return new Color(216,216,100);
		default:
			return new Color(0,0,0);
		}
	}

	/**
	 * return resources baed on land type
	 * @return resource amount
	 */
	public int[] getResource(){
		//wood, stone, food
		switch(type){
		case 1:
			int[] result= {3,1,1};
			return result;
		case 2:
			int[] result2= {0,1,1};
			return result2;
		case 3:
			int[] result3={0,0,4};
			return result3;
		case 4:
			int[] result4={0,2,-1};
			return result4;
		default:
			int[] resultD={0,0,0};
			return  resultD;
		}
	}

	/**
	 * returns land type
	 * @return
	 */
	public int getType() {
		return type;
	}

	/**
	 * sets land type
	 * @param type
	 */
	public void setType(int type) {
		this.type = type;
	}

	/**
	 * adds unit to this land
	 * @param u - unit
	 */
	public void addUnit(Unit u) {
		if(unit != null) {
			JOptionPane.showMessageDialog(new JFrame(), "OCCUPIED");
		} else
			unit = u;
	}
	
	/**
	 * removes dead units
	 */
	public void cleanUnit() {
		if(unit!=null && !unit.isAlive())
			clearUnit();
	}

	/**
	 * kills unit on this land
	 */
	public void clearUnit() {
		unit = null;
	}

	/**
	 * returns unit on this land
	 * @return unit
	 */
	public Unit getUnit() {
		return unit;
	}

	/**
	 * adds city to this land
	 * @param c city
	 */
	public void addCity(City c) {
		if(city != null) {
			System.err.println("OCCUPIED");
		} else
			city = c;
	}

	/**
	 * returns colony on this land
	 * @return
	 */
	public Colony getColony() {
		return colony;
	}

	/**
	 * adds colony to this land
	 * @param c
	 */
	public void addColony(Colony c) {
		if(colony != null) {
			System.err.println("OCCUPIED");
		} else
			colony = c;
	}

	/**
	 * returns city on this land
	 * @return
	 */
	public City getCity() {
		return city;
	}
}
